bitkeeper revision 1.1426.1.1 (4289cc8cPUM98bLJs4TV93NHY9LOKg)
authorcl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Tue, 17 May 2005 10:50:52 +0000 (10:50 +0000)
committercl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Tue, 17 May 2005 10:50:52 +0000 (10:50 +0000)
Many files:
  Make interface to network/block scripts consistent:
  - output on stdout is returned to the script caller
  - output on stderr is logged at the error level, messages with a '-' prefix
    are logged at the debug level and messages with a '*' prefix are logged
    at the info level.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
tools/examples/block-enbd
tools/examples/block-file
tools/examples/network
tools/examples/network-nat
tools/examples/vif-bridge
tools/examples/vif-nat
tools/examples/vif-route
tools/python/xen/util/process.py
tools/python/xen/xend/Blkctl.py
tools/python/xen/xend/Vifctl.py

index cfae6288b26829ddebf540b141340c85621b5c03..a8fa108f0de052022f46cc99e29595387e69e95c 100755 (executable)
@@ -27,7 +27,7 @@ case $1 in
        ;;
 
        *)
-               echo 'Unknown command: ' $1
-               echo 'Valid commands are: bind, unbind'
+               echo 'Unknown command: ' $1 >&2
+               echo 'Valid commands are: bind, unbind' >&2
                exit 1
 esac
index 362b1faee592011590019ba27f1e35561c0b6a7b..a1612b6d47cafb40535c43feb9073c97cbb91d1d 100755 (executable)
@@ -25,7 +25,7 @@ case $1 in
        ;;
 
        *)
-               echo 'Unknown command: ' $1
-               echo 'Valid commands are: bind, unbind'
+               echo 'Unknown command: ' $1 >&2
+               echo 'Valid commands are: bind, unbind' >&2
                exit 1
 esac
index 12ff1c5eee0284a7e5ac5abe28afda3f9676eaf0..47daae95b0efb125a829a52b9eb7caf5af43f8ef 100755 (executable)
@@ -53,7 +53,7 @@ bridge=${bridge:-xen-br0}
 netdev=${netdev:-eth0}
 antispoof=${antispoof:-yes}
 
-echo "network $OP bridge=$bridge netdev=$netdev antispoof=$antispoof"
+echo "*network $OP bridge=$bridge netdev=$netdev antispoof=$antispoof" >&2
 
 # Usage: transfer_addrs src dst
 # Copy all IP addresses (including aliases) from device $src to device $dst.
@@ -232,7 +232,7 @@ case ${OP} in
        ;;
 
     *)
-       echo 'Unknown command: ' ${OP}
-       echo 'Valid commands are: start, stop, status'
+       echo 'Unknown command: ' ${OP} >&2
+       echo 'Valid commands are: start, stop, status' >&2
        exit 1
 esac
index e0050a4e7201d1428a6ce8ce06bf519e84462411..0d6460f30819a7ba5e4f574884e777cd3e923986 100644 (file)
@@ -32,7 +32,7 @@ netdev=${netdev:-eth0}
 # antispoofing not yet implemented
 antispoof=${antispoof:-no}
 
-echo "network-nat $OP netdev=$netdev antispoof=$antispoof"
+echo "*network-nat $OP netdev=$netdev antispoof=$antispoof" >&2
 
 
 op_start() {
@@ -71,7 +71,7 @@ case ${OP} in
        ;;
 
     *)
-       echo 'Unknown command: ' ${OP}
-       echo 'Valid commands are: start, stop, status'
+       echo 'Unknown command: ' ${OP} >&2
+       echo 'Valid commands are: start, stop, status' >&2
        exit 1
 esac
index 42bdf0e17344223b63bb34e55cab87f4ba81533f..1c5bc161f90a3c1ae1393ee25762a9836416a801 100755 (executable)
@@ -34,7 +34,7 @@
 # Exit if anything goes wrong
 set -e 
 
-echo "vif-bridge $*"
+echo "*vif-bridge $*" >&2
 
 # Operation name.
 OP=$1
@@ -63,8 +63,8 @@ case $OP in
         iptcmd='-D'
         ;;
     *)
-        echo 'Invalid command: ' $OP
-        echo 'Valid commands are: up, down'
+        echo 'Invalid command: ' $OP >&2
+        echo 'Valid commands are: up, down' >&2
         exit 1
         ;;
 esac
index 4b6d348dfaaa149acc4e25b3056215027611f66c..00977f881983b27fb82bf4769342483f8d53e0d4 100644 (file)
@@ -23,7 +23,7 @@
 # Exit if anything goes wrong
 set -e 
 
-echo "vif-nat $*"
+echo "*vif-nat $*" >&2
 
 # Operation name.
 OP=$1
@@ -56,8 +56,8 @@ case $OP in
         ipcmd='d'
         ;;
     *)
-        echo 'Invalid command: ' $OP
-        echo 'Valid commands are: up, down'
+        echo 'Invalid command: ' $OP >&2
+        echo 'Valid commands are: up, down' >&2
         exit 1
         ;;
 esac
index b15aea1e5c16dd9ff0ae86288ee41be1dfe02fb8..e2ff8b0f198dc06389fc72c4a434caa4439c679c 100755 (executable)
@@ -24,7 +24,7 @@
 # Exit if anything goes wrong
 set -e 
 
-echo "vif-route $*"
+echo "*vif-route $*" >&2
 
 # Operation name.
 OP=$1
@@ -57,8 +57,8 @@ case $OP in
         ipcmd='d'
         ;;
     *)
-        echo 'Invalid command: ' $OP
-        echo 'Valid commands are: up, down'
+        echo 'Invalid command: ' $OP >&2
+        echo 'Valid commands are: up, down' >&2
         exit 1
         ;;
 esac
index f6aac50f5b5fdb1c4b3225e899d85765e0e02ec2..07bc73b5053a693a51caf0e1e2d3ec4610a1d38d 100644 (file)
@@ -4,10 +4,11 @@
 
 import popen2
 import select
+import string
 
 from xen.xend.XendLogging import log
 
-def system(cmd):
+def runscript(cmd):
     # split after first space, then grab last component of path
     cmdname = "[%s] " % cmd.split()[0].split('/')[-1]
     # run command and grab stdin, stdout and stderr
@@ -18,14 +19,19 @@ def system(cmd):
     p = select.poll()
     p.register(cout)
     p.register(cerr)
+    stdout = ""
     while True:
         r = p.poll()
         for (fd, event) in r:
             if event == select.POLLHUP:
-                return
+                return stdout
             if fd == cout.fileno():
-                l = cout.readline()
-                log.info(cmdname + l.rstrip())
+                stdout = stdout + cout.readline()
             if fd == cerr.fileno():
                 l = cerr.readline()
-                log.error(cmdname + l.rstrip())
+                if l[0] == '-':
+                    log.debug(cmdname + l[1:].rstrip())
+                elif l[0] == '*':
+                    log.info(cmdname + l[1:].rstrip())
+                else:
+                    log.error(cmdname + l.rstrip())
index d90c7ce51df0981487eeab447046543499c728af..0b46f54079da1c6d69540180d9a44174e0c296a5 100644 (file)
@@ -4,6 +4,7 @@ import os
 import os.path
 import sys
 import string
+import xen.util.process
 
 from xen.xend import XendRoot
 
@@ -38,8 +39,6 @@ def block(op, type, dets, script=None):
     script = os.path.join(SCRIPT_DIR, script)
     args = [op] + string.split(dets, ':')
     args = ' '.join(args)
-    out = os.popen(script + ' ' + args)
-
-    output = _readline(out)
-    out.close()
-    return string.rstrip(output)
+    ret = xen.util.process.runscript(script + ' ' + args)
+    if len(ret):
+        return ret.splitlines()[0]
index d26f78d7a03a145a3b6bc3662a08eb220039cc24..0bc58f44809751de050736c4f412885bebf294ee 100644 (file)
@@ -36,7 +36,9 @@ def network(op, script=None, bridge=None, antispoof=None):
     else:
         args.append("antispoof=no")
     args = ' '.join(args)
-    xen.util.process.system(script + ' ' + args)
+    ret = xen.util.process.runscript(script + ' ' + args)
+    if len(ret):
+        return ret.splitlines()[0]
 
 def set_vif_name(vif_old, vif_new):
     if vif_old == vif_new:
@@ -81,5 +83,6 @@ def vifctl(op, vif=None, script=None, domain=None, mac=None, bridge=None, ipaddr
         ips = ' '.join(ipaddr)
         args.append("ip='%s'" % ips)
     args = ' '.join(args)
-    os.system(script + ' ' + args)
-
+    ret = xen.util.process.runscript(script + ' ' + args)
+    if len(ret):
+        return ret.splitlines()[0]